<?php
/**
 * 充值审核
 *
 * @author Alen
 * @since 1.0.0 2013-12-6 sutroon
 */
class Finance_Recharge_EditAction extends AdmincpAction {
    //put your code here
    public function index(){
        
        $sn=request_string('n');
        
        if(!$sn) redirect('参数丢失','?m=Finance_Recharge_List');
        
        // 获取主键编号
        $id=request_numeric('id');
        
        // 读取数据     
        $biz=new SoBizRecharge();
        $data=$biz->read_one($sn);
        if(!$data) redirect('充值记录不存在','?m=Finance_Recharge_List');
        
        // 判断资金账户状态是否正常
        $acc=new SoBizFinanceAccount();
        $state=$acc->get_state($data['UserName']);
        if(!$state) redirect($data['UserName'].'账户状态异常','?m=Finance_Recharge_List');
        
        // 设置页面信息,如页面标题,meta信息等
        $this->set_page_info($sn);
        
        // 构建表单内容
        $this->uig->begin_form();
        $this->uig->add_staticfield('流水号', $sn);
        $this->uig->add_staticfield('用户名', $data['UserName']);
        $this->uig->add_staticfield('充值金额', $data['Amount']);
        $this->uig->add_staticfield('交易流水号', $data['BankTransactionSN']);
        $this->uig->add_staticfield('开户行名称', $data['BankName']);
        $this->uig->add_staticfield('持卡人名字', $data['BankCardHolder']);
        $this->uig->add_staticfield('申请日期', $data['CreatedTime']);
        $this->uig->add_staticfield('用户备注', $data['UserRemark']);
        $this->uig->add_radiofield('审核结果', 'State', array('未审核'=>0,'通过'=>1,'不通过'=>4),$data['State']);
        $this->uig->add_textareafield('审核说明', 'AdminRemark',$data['AdminRemark']);
        $this->uig->add_controlfield(array('save_with_confirm'));
        $this->uig->add_hiddenfield(array('action'=>'save'));
        $this->uig->end_form();
        $this->assign('form', $this->uig->get_text()); 
        
        // 显示模板
        $this->display();
        
    }
    
    public function save(){ 
        $sn=request_string('n');
        if(!$sn) redirect ('参数无效');
        $biz=new SoBizRecharge();
        $data=$biz->read_one($sn);
        if(!$data) redirect('充值记录不存在','?m=Finance_Recharge_List'); 
        $msg=$biz->confirm_by_admin($sn, $data['UserName'], request_numeric('State'), $data['Amount'], request_string('AdminRemark'));
        
	redirect($msg=='SUCCESS'?'审核提交成功':$msg,'?m=Finance_Recharge_List');        
    }
}